package com.fly.core;

import java.util.LinkedList;
import java.util.List;

/**
 * 分页对象
 * 
 * @author 00fly
 * @version [版本号, 2016-3-6]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class PaginationSupport
{
    private long currentPage; // 当前页
    
    private long total; // 总记录数
    
    private int pageSize; // 每页大小
    
    private long totalPage; // 总页数
    
    private long previous; // 上一页
    
    private long next; // 下一页
    
    private List<?> items; // 当前页的数据
    
    @SuppressWarnings("rawtypes")
    public PaginationSupport(long total, int pageNo, int pageSize)
    {
        items = new LinkedList();
        this.pageSize = pageSize;
        currentPage = pageNo;
        setTotal(total);
    }
    
    public long getCurrentPage()
    {
        return currentPage;
    }
    
    public void setCurrentPage(int currentPage)
    {
        this.currentPage = currentPage;
    }
    
    public long getTotal()
    {
        return total;
    }
    
    public void setTotal(long totalcount)
    {
        total = totalcount;
        if (totalcount == 0)
        {
            totalPage = 0;
        }
        else
        {
            totalPage = 1 + (totalcount - 1) / pageSize;
        }
        if (currentPage < 1)
        {
            currentPage = 1;
        }
        else if (currentPage > totalPage)
        {
            currentPage = totalPage;
        }
        if (1 == currentPage)
        {
            previous = 1;
        }
        else
        {
            previous = currentPage - 1;
        }
        if (totalPage == currentPage)
        {
            next = currentPage;
        }
        else
        {
            next = currentPage + 1;
        }
    }
    
    public int getPageSize()
    {
        return pageSize;
    }
    
    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }
    
    public long getTotalPage()
    {
        return totalPage;
    }
    
    public void setTotalPage(long totalPage)
    {
        this.totalPage = totalPage;
    }
    
    public long getPrevious()
    {
        return previous;
    }
    
    public void setPrevious(long previous)
    {
        this.previous = previous;
    }
    
    public long getNext()
    {
        return next;
    }
    
    public void setNext(long next)
    {
        this.next = next;
    }
    
    public List<?> getItems()
    {
        return items;
    }
    
    public void setItems(List<?> items)
    {
        this.items = items;
    }
}
